var util = require('../../../utils/activitytime.js'); 
var QQMapWX = require('../../../utils/qqmap-wx-jssdk.js');
var qqmapsdk;
var remoteUrl = getApp().globalData.remoteurl;
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    date: '',
    time: '',
    currentTime:'',
    currentDate:'',
  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  bindTimeChange: function (e) {
    this.setData({
      time: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    qqmapsdk = new QQMapWX({
      key: 'M7CBZ-AEJCG-OUJQC-IE75K-YIHBJ-2VF2J'
    });
    that = this;
    var date = util.formatDate(new Date());  
    var time = util.formatTime(new Date());
    this.setData({
      time: time,
      date: date,
      currentTime:time,
      currentDate:date,
      petId:options.petId
    })
  },
  formSubmit:function(e){
    var time = this.data.date + " " + this.data.time;
    wx:wx.request({
      url: remoteUrl + "createActivity",     
      data:{
        title:e.detail.value.name,
        address:e.detail.value.address,
        information:e.detail.value.introduction,
        time:time,
        petId:that.data.petId
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function(res) {
        wx:wx.showToast({
          title: '创建活动成功',
          icon: 'none',
          duration: 1500,
          success: function (res) {
            wx: setTimeout(function () {
              wx:wx.switchTab({
                url: '/pages/index/index',
              })
            }, 1500)
          },
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  test:function(e){
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (addressRes) {
            that.setData({
              address:addressRes.result.address
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
})